package GoodsPackage;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/SearchGood.do")
public class SearchGoodServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        GoodsDao bookDao = new GoodsDao();
        String searchQuery = request.getParameter("searchQuery");

        List<Good> goods = bookDao.searchGood(searchQuery);

        // 将商品列表存入session
        HttpSession session = request.getSession();
        session.setAttribute("goods", goods);

        // 重定向到相应的JSP页面
        response.sendRedirect("search.jsp");
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}
